home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Source utilities for endian conversion
- Date: 29 Jan 1996 18:23:41 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4ejvfdINN4tg@keats.ugrad.cs.ubc.ca>
- References: <rt9sph42r1m.fsf@topo.nist.gov>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <rt9sph42r1m.fsf@topo.nist.gov>,
- Paul J Sullivan <sullypj@topo.nist.gov> wrote:
- >I am trying to write a routine (c is not my first language) that will
- >allow me to read a binary data file on various platforms. I have
- >encountered the -endian problem and, thus, was wondering what routines
- >exist to convert between big- and little- formats. Is it possible to
- >do this without the conversion i.e. somehow specify a directive?? Is
- >it in a FAQ?
-
- Try Sun XDR. I use it. It's not bad. It exists in freely distributed form.
-
- XDR gives you tools to serialize basic data types into memory buffers or
- standard I/O streams, and to deserialize them.
-
- You create an XDR stream like this:
-
- XDR encode;
- char mybuffer[1024];
- long a = 3;
- char c = 'a';
-
- xdrmem_create(&encode, mybuffer, 1024, XDR_ENCODE);
-
- xdr_long(&encode, &a);
- xdr_char(&encode, &c);
-
- printf("Encoded bytes: %d\n", xdr_getpos(&encode));
-
- The ``rpcgen'' utility will automatically generate routines which recursively
- pack and unpack complex data structures from C-like structure definitions, and
- will also produce C headers declaring these structures.
-
- >Appreciate the help.
- >
- >
- >--
- >Paul
- >
- > -----------------------------------------------------
- >| Dr Paul J. Sullivan sullypj@enh.nist.gov |
- >| National Institute of Standards & Technology (NIST) |
- >| Tel: (301) 975 6386 Fax: (301) 869 0822 |
- >| http://www.coe.uncc.edu/~pjsulliv/ |
- > -----------------------------------------------------
-
-
- --
-
-